/* 2016/5/2 */
package com.cosmos.pictureswitcher.wallpaper;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.NonNull;

import java.io.IOException;

public class WallpaperUtil {

    public static void setWallpaperByFile(Context context, String filePath)
            throws IOException {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
        /*Resources res = getResources();
        Bitmap bitmap = BitmapFactory.decodeResource(res, getResources().getIdentifier(
                "wallpaper", "drawable", "com.co"));*/
        Bitmap bitmap = BitmapFactory.decodeFile(filePath);
        wallpaperManager.setBitmap(bitmap);
    }

    public static void setWallpaperByResource(Context context, String name) throws IOException {
        WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
        wallpaperManager.setResource(context.getResources().getIdentifier(
                "wallpaper", "drawable", "com.co"));
    }
}
